<template>
  <a-card :bordered="false">
    <div style="color: orange;margin-bottom: 20px;">{{$t('说明：新系统初装或加订新设备，请联系系统提供商获取设备授权文件并导入系统，否则您的设备将不能正常使用')}}</div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-upload v-has="'BisDeviceCertController:import'" accept=".ert" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">{{$t('导入授权文件')}}</a-button>
      </a-upload>
      <a-button v-has="'BisDeviceCertController:sync'" type="primary" @click="handleSync">{{$t('同步授权文件')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { postAction } from '@/api/manage'

  export default {
    name: 'BisDeviceCertList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
    },
    data () {
      return {
        description: '设备授权管理页面',
        // 表头
        columns: [
          {
            title:this.$t('产品编码'),
            align:"center",
            dataIndex: 'deviceType'
          },
          {
            title:this.$t('产品名称'),
            align:"center",
            dataIndex: 'deviceName'
          },
          {
            title:this.$t('授权数量'),
            align:"center",
            dataIndex: 'certNum'
          },
          {
            title:this.$t('在用数量'),
            align:"center",
            dataIndex: 'useNum'
          }
        ],
        url: {
          list: "/device/bisDeviceCert/list",
          importExcelUrl: "device/bisDeviceCert/importCert",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleSync(){
        let that = this
        postAction('/device/bisDeviceCert/syncCert').then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.searchQuery();
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'deviceType',text:'产品编码',dictCode:''})
        fieldList.push({type:'string',value:'deviceName',text:'产品名称',dictCode:''})
        fieldList.push({type:'int',value:'certNum',text:'授权数量',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>